package model.location;

/**
 * An area with a coordinate, width and height.
 * <p>Coordinate represents the upper left corner</p>
 */
public abstract class Area 
{
	protected Coordinate _coordinate;
	protected Dimension _dimension;
	
	protected float[] _points;
	
	public Area(Coordinate coordinate, Dimension dimension)
	{
		_coordinate = coordinate;
		_dimension = dimension;
		
		setPoints();
	}
	
	public Area(Coordinate coordinate, Dimension dimension, boolean fromCenter)
	{
		// Area itself does not use this constructor, but the subclasses do.
	}

	public Coordinate getCoordinate() {
		return _coordinate;
	}

	public void setCoordinate(Coordinate coordinate) {
		_coordinate = coordinate;
	}

	public Dimension getDimension() {
		return _dimension;
	}

	public void setDimension(Dimension dimension) {
		_dimension = dimension;
	}
	
	/**
	 * Gets the coordinate representing the center of this area.
	 * @return The center coordinate.
	 */
	public abstract Coordinate getCenterCoord();
	
	/**
	 * Gets the points representing the four corners of this area.
	 * @return A float array representing the four corners of the area in order: 
	 * <br>- Upper left
	 * <br>- Upper right
	 * <br>- Lower left
	 * <br>- Lower right
	 */
	public float[] getPoints()
	{
		if(_points == null)
			setPoints();
		return _points;
	}
	
	/**
	 * Sets the points representing the four corners of this area.
	 * <p>
	 * in order: 
	 * <br>- Upper left
	 * <br>- Upper right
	 * <br>- Lower left
	 * <br>- Lower right
	 * </p>
	 */
	public abstract void setPoints();
	
	@Override
	public String toString() 
	{
		return String.format("UpperLeft: %s - Center: %s\nDimension: %s", _coordinate.toString(), getCenterCoord().toString(), _dimension.toString());
	}
}
